/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.metadataRepository.analysis;

import cz.mzk.oai.metadataRepository.repository.Identifier;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Martin Řehánek (rehan at mzk.cz)
 */
public class MultisetSizeCounters {

    //private final Map<Multiset<String>, Integer> multisetOccuranceMap;
    //private Map<Multiset<String>, Integer> multisetOccuranceMap;
    private int single = 0;
    private int missing = 0;
    private int multiple = 0;

//    public MultisetSizeCounters(Map<Multiset<String>, Integer> multisetOccuranceMap) {
//        this.multisetOccuranceMap = multisetOccuranceMap;
//        loadCounters();
//    }
    
    public static MultisetSizeCounters byMultisetOccuranceMap(Map<Multiset<String>, Integer> multisetOccuranceMap){
        MultisetSizeCounters result = new MultisetSizeCounters();
        result.loadCountersFromOccurence(multisetOccuranceMap);
        return result;
    }

    public static MultisetSizeCounters byMultisetIdMap(Map<Multiset<String>, List<Identifier>> multisetIdlistMap){
        MultisetSizeCounters result = new MultisetSizeCounters();
        result.loadCountersFromIdList(multisetIdlistMap);
        return result;
    }


    public void loadCountersFromIdList(Map<Multiset<String>, List<Identifier>> multisetIdlistMap){
        for (Multiset<String> value : multisetIdlistMap.keySet()) {
            int counter = multisetIdlistMap.get(value).size();
            switch (value.size()) {
                case 0:
                    missing += counter;
                    break;
                case 1:
                    single += counter;
                    break;
                default:
                    multiple += counter;
                    break;
            }
        }
    }

    public void loadCountersFromOccurence(Map<Multiset<String>, Integer> multisetOccuranceMap) {
        for (Multiset<String> value : multisetOccuranceMap.keySet()) {
            int counter = multisetOccuranceMap.get(value);
            switch (value.size()) {
                case 0:
                    missing += counter;
                    break;
                case 1:
                    single += counter;
                    break;
                default:
                    multiple += counter;
                    break;
            }
        }
    }



    public int single(){
        return single;
    }

    public int missing(){
        return missing;
    }

    public int multiple(){
        return multiple;
    }
}
